package com.mywork.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ciko.code.base.BaseActicity;
import com.ciko.code.bean.SelAcceptPlanEty;
import com.ciko.code.http.BaseResponse;
import com.ciko.code.http.Req.UpdatePlanStatusReq;
import com.ciko.code.utils.DateUtil;
import com.ciko.code.utils.ToastUtils;
import com.image_see.ImageSeeActivity;
import com.mywork.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;


/**
 * Created by ciko on 2015/12/8
 */
public class WorkPlaneReceiveDetailActivity
        extends
        BaseActicity
{
	
	private TextView		  tvtypePlane;
	private TextView		  tvtimePlane;
	private TextView		  tvcontectPlane;
	private TextView		  tvsummaryPlane;
	private TextView		  tvnextPlane;
	private TextView		  tvhelpPlane;
	private TextView		  tvremarkPlane;
	private TextView		  tvpersonPlane;
	private Button			  btnaccept;
	private EditText		  ed_text_comm;
	private SelAcceptPlanEty  selAcceptPlanEty;
	private TextView		  tvHeadName, tvHeadCommentName, tvContectPlan, tvNextPlan;
	private LinearLayout	  llHelp, llRemarks;
	private TextView		  tvCommentTime;
	private TextView		  tvFujian;
	private ImageView		  imgPic;
	private ArrayList<String> urlList = new ArrayList<>();
									  
	@Override
	protected void initTopBar() {
		
		selAcceptPlanEty = (SelAcceptPlanEty) getIntent().getSerializableExtra("SelAcceptPlanEty");
		
		setTitle("计划详情");
		enableNavLeftImg();
	}
	
	@Override
	protected void initLayout() {
		setContentView(R.layout.activity_work_plane_receive_detail);
		
	}
	
	@Override
	protected void initView() {
		tvContectPlan = (TextView) findViewById(R.id.tv_contectPlane1);
		tvNextPlan = (TextView) findViewById(R.id.tv_nextPlane1);
		llHelp = (LinearLayout) findViewById(R.id.ll_help);
		llRemarks = (LinearLayout) findViewById(R.id.ll_remarks);
		tvHeadName = (TextView) findViewById(R.id.tv_head_img_name);
		tvHeadCommentName = (TextView) findViewById(R.id.tv_head_comment_name);
		btnaccept = (Button) findViewById(R.id.btn_accept);
		
		tvpersonPlane = (TextView) findViewById(R.id.tv_personPlane);
		tvremarkPlane = (TextView) findViewById(R.id.tv_remarkPlane);
		tvhelpPlane = (TextView) findViewById(R.id.tv_helpPlane);
		tvnextPlane = (TextView) findViewById(R.id.tv_nextPlane);
		tvsummaryPlane = (TextView) findViewById(R.id.tv_summaryPlane);
		tvcontectPlane = (TextView) findViewById(R.id.tv_contectPlane);
		tvtimePlane = (TextView) findViewById(R.id.tv_timePlane);
		tvtypePlane = (TextView) findViewById(R.id.tv_typePlane);
		ed_text_comm = (EditText) findViewById(R.id.ed_text_comm);
		imgPic = (ImageView) findViewById(R.id.img_pic);
		tvFujian = (TextView) findViewById(R.id.tvFujian);
	}
	
	@Override
	protected void initAdapter() {
	
	}
	
	@Override
	protected void initDates() {
		tvCommentTime = (TextView) findViewById(R.id.tv_detail_commit_time);
		tvHeadName.setText(selAcceptPlanEty.getCreateName());
		tvHeadCommentName.setText(selAcceptPlanEty.getAcceptName());
		tvpersonPlane.setText(selAcceptPlanEty.getCreateName());
		tvremarkPlane.setText((selAcceptPlanEty.getRemarks() == null ? "" : selAcceptPlanEty.getRemarks()));
		tvhelpPlane.setText((selAcceptPlanEty.getHelp() == null ? "" : selAcceptPlanEty.getHelp()));
		tvnextPlane.setText((selAcceptPlanEty.getWorkPlan() == null ? "" : selAcceptPlanEty.getWorkPlan()));
		tvsummaryPlane.setText((selAcceptPlanEty.getWorkSummary() == null ? "" : selAcceptPlanEty.getWorkSummary()));
		tvcontectPlane.setText((selAcceptPlanEty.getCompleteWork() == null ? "" : selAcceptPlanEty.getCompleteWork()));
		tvtimePlane.setText("提交时间:" + DateUtil.longToDate(selAcceptPlanEty.getCreateTime(), 8));
		llRemarks.setVisibility(selAcceptPlanEty.getRemarks() == null || selAcceptPlanEty.getRemarks().equals("") ? View.GONE : View.VISIBLE);
		llHelp.setVisibility(selAcceptPlanEty.getHelp() == null || selAcceptPlanEty.getHelp().equals("") ? View.GONE : View.VISIBLE);
		if (selAcceptPlanEty.getEnclosure().equals(""))
		{
			imgPic.setVisibility(View.GONE);
			tvFujian.setVisibility(View.GONE);
		}
		else
		{
			Picasso.with(this).load(selAcceptPlanEty.getEnclosure()).placeholder(R.drawable.bg_small_image).into(imgPic);
			urlList.add(selAcceptPlanEty.getEnclosure());
		}
		switch (selAcceptPlanEty.getPlanType()) {
			case "周报":
				tvtypePlane.setText("周报");
				tvContectPlan.setText("本周工作情况");
				tvNextPlan.setText("下周工作计划");
				break;
			case "月报":
				tvtypePlane.setText("月报");
				tvContectPlan.setText("本月工作情况");
				tvNextPlan.setText("下月工作计划");
				break;
			case "季报":
				tvtypePlane.setText("季报");
				tvContectPlan.setText("本季工作情况");
				tvNextPlan.setText("下季工作计划");
				break;
				
		}
		
		switch (selAcceptPlanEty.getStatus()) {
			case "1":
				findViewById(R.id.llyt_accept_reject).setVisibility(View.VISIBLE);
				break;
			case "2":
				ed_text_comm.setEnabled(false);
				ed_text_comm.setFocusable(false);
				findViewById(R.id.llyt_accept_reject).setVisibility(View.GONE);
				ed_text_comm.setEnabled(false);
				ed_text_comm.setFocusable(false);
				break;
			case "3":
				findViewById(R.id.llyt_accept_reject).setVisibility(View.GONE);
				ed_text_comm.setEnabled(false);
				ed_text_comm.setFocusable(false);
				break;
			case "4":
				findViewById(R.id.llyt_accept_reject).setVisibility(View.GONE);
				ed_text_comm.setEnabled(false);
				ed_text_comm.setFocusable(false);
				break;
				
		}
		ed_text_comm.setText(selAcceptPlanEty.getComment() + "");
		tvCommentTime.setText(getString(R.string.approval_time, selAcceptPlanEty.getModifyTimeStr()));
		tvCommentTime.setVisibility(selAcceptPlanEty.getStatus().equals("1") ? View.GONE : View.VISIBLE);
	}
	
	@Override
	protected void initListener() {
		btnaccept.setOnClickListener(this);
		imgPic.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		super.onClick(v);
		if (v == btnaccept)
		{
			doRequestHttp(new UpdatePlanStatusReq(selAcceptPlanEty.getPlanId(), "3", ed_text_comm.getText().toString()));
		}
		
		if (v == imgPic)
		{
			Intent intent = new Intent(WorkPlaneReceiveDetailActivity.this, ImageSeeActivity.class);
			intent.putStringArrayListExtra("urlList", urlList);
			startActivity(intent);
		}
		//        switch (v.getId()) {
		//            case R.id.btn_accept:
		//                doRequestHttp(new UpdatePlanStatusReq(selAcceptPlanEty.getPlanId(), "3", ed_text_comm.getText().toString()));
		//                break;
		//            case R.id.btn_reject:
		//                doRequestHttp(new UpdatePlanStatusReq(selAcceptPlanEty.getPlanId(), "2", ed_text_comm.getText().toString()));
		//                break;
		//        }
	}
	
	@Override
	public void onResponseSuccess(BaseResponse<?> response, String tag) {
		super.onResponseSuccess(response, tag);
		
		ToastUtils.showShort("操作成功");
		Intent intent = new Intent();
		setResult(1000, intent);
		finish();
		
	}
}
